﻿using System;
using System.Collections.Generic;
using System.Data;
using Loki.Data;
using Luna.Data.Configuration;

namespace Luna.Data.CRM
{
    /// <summary>
    /// Mapper for data interface IAccountData.
    /// </summary>
    public partial class AccountDataMapper : LunaEntityMapper<AccountData, IAccountData> 
    {
        public AccountDataMapper()
        {
            GetAllRequest = "Crm.account_select_all";
            GetRequest = "Crm.account_select";
            InsertRequest = "Crm.account_insert";
            UpdateRequest = "Crm.account_update";
            DeleteRequest = "Crm.account_delete";
        }
        
        private const string CategoryIDColumnName = "CategoryID";
        private const string NameColumnName = "Name";
        private const string AddressColumnName = "Address";
        private const string ZipCodeColumnName = "ZipCode";
        private const string CityColumnName = "City";
        private const string CountryColumnName = "Country";
        private const string UrlColumnName = "Url";
        private const string CommentColumnName = "Comment";

        protected override void LoadCoreData(IAccountData entity, IDataRecord record)
        {
            entity.CategoryID = record.GetNullableGuid(CategoryIDColumnName);
            entity.Name = record.GetString(NameColumnName);
            entity.Address = record.GetString(AddressColumnName);
            entity.ZipCode = record.GetString(ZipCodeColumnName);
            entity.City = record.GetString(CityColumnName);
            entity.Country = record.GetString(CountryColumnName);
            entity.Url = record.GetString(UrlColumnName);
            entity.Comment = record.GetString(CommentColumnName);
        }
        
        protected override void MapSaveParameters(IDatabaseCommand command, IAccountData entity)
        {
            command.AddParameter(CategoryIDColumnName, entity.CategoryID);
            command.AddParameter(NameColumnName, entity.Name);
            command.AddParameter(AddressColumnName, entity.Address);
            command.AddParameter(ZipCodeColumnName, entity.ZipCode);
            command.AddParameter(CityColumnName, entity.City);
            command.AddParameter(CountryColumnName, entity.Country);
            command.AddParameter(UrlColumnName, entity.Url);
            command.AddParameter(CommentColumnName, entity.Comment);
            command.AddParameter(IDParameterName, entity.PK);
        }
           
    }
}